﻿
using HBase;
using System.Collections.Generic;
namespace hCommand {
    public abstract class AbsWcs2WmsTask :ZtTask {

        protected IWCSServer wcsServer = WMSDalFactray.getDal<IWCSServer>();

        void finshParam() {
            List<CoreTaskParam> paramList = MyCache.getList<CoreTaskParam>();
            foreach( CoreTaskParam p in paramList ) {
                Node node = MyCache.queryUnique<Node>((a) => {
                    return a.isConfig(p.des);
                } ,"CompleteParam des 过多" + p.des);

                Estimate fe = node.getCurrent();
                if( fe != null && fe.taskNo == p.taskNo ) {
                    p.status = ( int ) CoreTaskParamStatus.执行结束;
                    p.cDes = p.des;
                }
            }
        }
        public override bool excute() {


            finshParam();

            List<CoreTaskParam> list = MyCache.query<CoreTaskParam>((a) => {
                return a.uploaded == 0;
            });
            foreach( CoreTaskParam param in list ) {
                bool res = false;
                if( param.status == ( int ) CoreTaskParamStatus.满放变更 ) {
                    res = putFull(param);
                } else if( param.status == ( int ) CoreTaskParamStatus.空取 ) {
                    res = getEmply(param);
                } else if( isFinsh(param) ) {
                    if( commit(param) ) {
                      

                        Node node = MyCache.queryUnique<Node>((a) => {
                            return a.isConfig(param.des);
                        } ,"CompleteParam des 过多" + param.des);

                        Estimate e = node.getCurrent();
                        if(e!=null&& e.taskNo == param.taskNo ) {

                            node.clearCurrent(e.myOrder);
                        }
                        PathFacade.removeComplete(param.taskId);
                    }

                }

            }
            return true;
        }
        public virtual bool isFinsh(CoreTaskParam param) {
            if( param.status == ( int ) CoreTaskParamStatus.执行结束 ) {
                return param.cDes == param.des || param.cStn == param.des;
            }
            return false;
        }
        public abstract bool putFull(CoreTaskParam param);
        public abstract bool getEmply(CoreTaskParam param);

        public abstract bool commit(CoreTaskParam param);
    }
}
